package main

import (
	dbpl "DBPool"
	//"errors"
	"deps"
	"fmt"
)

const (
	DBPOOL_CONFIG_FILE = "../config/dbpool.xml"
)

var (
	g_dbpool *dbpl.DBPool
)

func init() {
	xml := &dbpl.XmlDBPoolConfig{}

	if err := deps.LoadConf(DBPOOL_CONFIG_FILE, xml); err != nil {
		panic("load config err" + err.Error())
	}

	pool, err := dbpl.NewDBPool(xml)
	if err != nil {
		panic("new db pool err" + err.Error())
	}
	g_dbpool = pool
}

func main() {

	insert := &InsertUserInfo{
		uid:  "111",
		name: "threadfly",
		age:  24,
		sex:  uint8(MAN),
	}

	g_dbpool.Write(insert)

	query := &QueryUserInfo{
		uid: "111",
		ret: make(chan map[string]string),
	}

	g_dbpool.Write(query)

	ret := <-query.Result()

	fmt.Printf("\nuid:%s name:%s age:%s sex:%s\n",
		ret["uid"],
		ret["name"],
		ret["age"],
		ret["sex"])
	g_dbpool.Stop()
}
